package Model;
import java.util.ArrayList;

/**
 * this class contains all the orders. we can use this to make daily rapports. 
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class OrdreContainer
{
    private static OrdreContainer instance;
    private ArrayList<Ordre> ordrelist;

    /**
     * Constructor for objects of class OrdreContainer
     */
    private OrdreContainer()
    {
        ordrelist = new ArrayList<Ordre>();
    }

    public static OrdreContainer getInstance()
    {
        if(instance == null)
        {
            instance = new OrdreContainer();
        }
        return instance;
    }

    /**
     * this method makes us capable of finding an order in the list
     * 
     * @param nothing
     * @return nothing
     */
    public Ordre findOrdre(int ordreNr)
    {
        int index = 0;
        while(ordrelist.size() > index)
        {
            Ordre ordre = ordrelist.get(index);
            if(ordre.getOrdreNr() == (ordreNr))
            {
                return ordre;
            }
            index++;
        }
        return null;
    }

    /**
     * this method makes it possible to remove an order
     * 
     * @param nothing
     * @return nothing
     */
    public void removeOrdre(int ordreNr)
    {
        ordrelist.remove(findOrdre(ordreNr));
    }

    /**
     * this method adds an order to the list
     * 
     * @param nothing
     * @return nothing
     */
    public void addOrdre(Ordre newOrdre)
    {
        //Ordre newOrdre = new Ordre(nr, dato);
        this.ordrelist.add(newOrdre);
    }

    /**
     * this method returns faktura from ordrelist
     * 
     * @param nothing
     * @return ordrelist.get(nr).myFaktura()
     */
    public String myFaktura()
    {
        int nr = 0;
        nr = ordrelist.size();
        nr -= 1;
        return ordrelist.get(nr).myFaktura();
    }
}
